home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 November / Macworld (1999-11).dmg / Updaters / WhiteCap 3.0.4 / WhiteCap Source.sit / WhiteCap Source / Common / io / Headers / CEgIStream.h < prev    next >
Text File  |  1999-07-13  |  3KB  |  91 lines

  1.  
  2. #ifndef _CEGISTREAM_
  3. #define _CEGISTREAM_
  4.  
  5.  
  6.  
  7.  
  8. #include "UtilStr.h"
  9. #include "CEgErr.h"
  10.  
  11.  
  12.  
  13.  
  14.  
  15. class CEgIStream : protected UtilStr, public virtual CEgErr {
  16.  
  17.     protected:
  18.         enum {
  19.             cDefaultBufSize                    = 5500
  20.         };
  21.         
  22.     public:
  23.  
  24.         
  25.                                         CEgIStream( unsigned short int inBufSize = cDefaultBufSize );
  26.         
  27.         // Client fcns...
  28.         long                            GetLong();
  29.         signed short int                GetShort();
  30.         unsigned char                    GetByte();
  31.         unsigned char                    PeekByte();
  32.         float                            GetFloat();
  33.         double                            GetDbl();
  34.         inline void                        Readln( UtilStr& outStr )                { Readln( &outStr );     }
  35.         void                            Readln( UtilStr* outStr );
  36.         void                            Readln();
  37.         void                            Read( UtilStr& outStr, unsigned long inBytes );
  38.         
  39.         //    Post:    Reads next token (tokens separated by a space or a CR,LF,TAB,SPACE). 
  40.         //    Note:    For Read( UtilStr& ), true is returned if a new line was reached.
  41.         float                            ReadFloat();
  42.         long                            ReadInt();
  43.         bool                            Read( UtilStr& outStr );
  44.         void                            Read();
  45.         
  46.         long                            GetBlock( void* destPtr, unsigned long inBytes );
  47.         virtual void                    skip( long inBytes );
  48.  
  49.         
  50.         unsigned char                    GetByteSW();
  51.         void                            ReadNumber( UtilStr& outStr );
  52.         bool                            AssertToken( const char* inStr );
  53.         
  54.         //    Post:    Reads <inBytes> worth of data from <inSource> and resets this stream for that data (at pos = 0)
  55.         //    Note:    These fcns are *only* designed as tools for using CEgIStream as a memory (RAM) stream!
  56.         void                            Assign( CEgIStream* inSource, long inBytes );
  57.         void                            Assign( void* inSource, long inBytes );
  58.         void                            Assign( const UtilStr& inSrce );
  59.         //    Post:    Resets this stream to the beginning of its buffer.  This should *only* in conjuction following
  60.         //            a call to Assign().  
  61.         void                            ResetBuf();
  62.         
  63.         //    Pre:    <inSrce> *cannot*, for obvious reasons, be destroyed before this is.
  64.         //    Post:    All subsequent 'Get...', skip, and Readln fcns will all read from <inSrce>
  65.         //    Note:    Call this fcn each time you want to reset it.
  66.         //     Note:    See that the difference between Tie and Assign is that Assign makes an independent copy of the data
  67.         void                            Tie( const UtilStr* inSrce );
  68.         void                            Tie( const char* inSrce, long inNumBytes = -1 );
  69.  
  70.  
  71.     
  72.     protected:
  73.         bool                            mIsTied;
  74.         unsigned short                    mReadBufSize;
  75.         const char*                        mNextPtr;                // Shortcut ptr to the data
  76.         long                            mBufPos;                // File pos where buf begins at (0 = begin of file, etc)
  77.         long                            mPos;                    // Virtual stream/file position
  78.  
  79.                 
  80.         void                            fillBuf();
  81.         void                            invalidateBuf();
  82.         virtual void                    fillBlock( unsigned long inStartPos, void* destPtr, long& ioBytes );
  83.         
  84.                 
  85.         static UtilStr                    sTemp;
  86. };
  87.  
  88.  
  89.  
  90. #endif
  91.